home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / exec / cupupdatematches.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  12KB  |  430 lines

  1. /* ***********************************************************************
  2.  
  3.    CUP UPDATE MATCHES PROGRAM FOR FOOTBALL REXX SUITE
  4.   ----------------------------------------------------
  5.                    Copyright  Mark Naughton 1997
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       071297   First release.
  11.            081297   Didn't write the ExtraTime and Penalties lines. While
  12.                     checking through the list from '.scf', the file is
  13.                     opened and each played match is written along with,
  14.                     if applicable, ET and Penalties lines. Added parsing
  15.                     to the matches just played to see if they fail any of
  16.                     the checks.
  17.            131297   Update didn't work. Only changed the first match. Had
  18.                     to rework the method to read the schedule first and
  19.                     then compare it with each line in matches. Now works
  20.                     properly.
  21.            141297   Added error message for Penalties.
  22.            151297   Added error message for Penalties being equal and
  23.                     tidied display.
  24.            280898   Added new error messages. Added pseudo code for
  25.                     addition of checks for Legs and Away Goals.
  26.            290898   Added code to parse 2nd leg matches.
  27.            050998   Amended code for away goals on extra time.
  28.            110998   Fixed major bug which rewrote the schedule file and
  29.                     missed several lines. When it reached the 2nd leg of
  30.                     the 2nd round, it missed the '#1st Leg' line in the
  31.                     recreation of the file. Its fixed and is trimmer than
  32.                     before.
  33.            120998   Amended match checking so if the score is level after
  34.                     extra time with goals scored then away goals count.
  35.            250899   Added error msg to file checks.
  36.  1.1       030999   Converted to use locale. Some error messages, before
  37.                     reading the locale, will still be in English.
  38.                     English language still needs to appear in the datafiles
  39.                     for processing by Football.
  40.  
  41. **************************************************************************
  42.  
  43. Procedure
  44. ---------
  45.  
  46. 1. Check files exist.
  47. 2. Read definition file and see if away goals are involved. Read in
  48.    temporary file from RAM: containing matches with scores entered from
  49.    FOOTBALL.
  50. 3. Read in '.scf' file.
  51. 4. Loop until all matches have been done; If a match hasn't been played
  52.    then overwrite it with the scores.
  53. 5. Open '.scf' file and write the newly amended data to it.
  54. 6. Exit.
  55.  
  56. ************************************************************************** */
  57. PARSE ARG league_stuff
  58.  
  59. version      = 1
  60. input_file   = 'RAM:Football.ctmpfile'
  61. input2_file  = '.scf'
  62. input3_file  = '.cf'
  63. matches.     = '???'
  64. separator    = '*'
  65. ttc          = 0
  66. not_played   = '__   __'
  67. league_file  = "Data/"league_stuff
  68. selines.     = '???'
  69. sdlines.     = '???'
  70. sdc          = 0
  71. awaygoals    = '*CUP_AWAYG='
  72.  
  73.  
  74. if open(datafile,"Data/Football.locale",'r') then do
  75.    line = readln(datafile)
  76.    locdir = strip(line)
  77.    close(datafile)
  78. end
  79. else do
  80.    say
  81.    say "ERROR :    (CupUpdateMatches)"
  82.    say
  83.    say "Cannot read 'Data/Football.locale' for the locale settings."
  84.    exit
  85. end
  86.  
  87. dcupdir = locdir"Football.locale_cup"
  88. locdir = locdir"Exec/CupUpdateMatches.data"
  89.  
  90. if open(datafile,"ENV:FootballRXPath",'r') then do
  91.    line = readln(datafile)
  92.    rxdir = strip(line)
  93.    close(datafile)
  94. end
  95. else
  96.    rxdir = "SYS:Rexxc/"
  97.  
  98. if exists(locdir) > 0 then do
  99.   address command rxdir'rx 'locdir
  100.   VarCount = getclip('VarCount')
  101.   do i = 1 to VarCount
  102.     interpret getclip('var.'i)
  103.   end
  104. end
  105. else do
  106.    say
  107.    say "ERROR :    (CupUpdateMatches)"
  108.    say
  109.    say "Cannot find '"locdir"' to read locale settings."
  110.    exit
  111. end
  112.  
  113. if exists(dcupdir) > 0 then do
  114.   address command rxdir'rx 'dcupdir
  115.   VarCount = getclip('VarCount')
  116.   do i = 1 to VarCount
  117.     interpret getclip('var.'i)
  118.   end
  119. end
  120. else do
  121.    say
  122.    say "ERROR :    (CupScheduler)"
  123.    say
  124.    say "Cannot find '"dcupdir"' to read cup locale settings."
  125.    exit
  126. end
  127.  
  128. if exists(input_file) = 0 then do
  129.    say
  130.    say cum_error
  131.    say
  132.    say cum_t2"'"input_file"'."
  133.    exit
  134. end
  135.  
  136. if exists(league_file||input2_file) = 0 then do
  137.    say
  138.    say cum_error
  139.    say
  140.    say cum_t2"'"league_file||input2_file"'."
  141.    exit
  142. end
  143.  
  144. if exists(league_file||input3_file) = 0 then do
  145.    say
  146.    say cum_error
  147.    say
  148.    say cum_t2"'"league_file||input3_file"'."
  149.    exit
  150. end
  151.  
  152. if open(datafile,league_file || input3_file,'r') then do
  153.    do while ~eof(datafile)
  154.       line = readln(datafile)
  155.       if pos(awaygoals,line) > 0 then awayg = delstr(line,1,11)
  156.    end
  157.    close(datafile)
  158. end
  159. else do
  160.    say
  161.    say cum_error
  162.    say
  163.    say cum_t3"'"league_file || input3_file"'."
  164.    exit
  165. end
  166.  
  167. ttc = 0
  168. if open(datafile,input_file,'r') then do
  169.    do while ~eof(datafile)
  170.       line = readln(datafile)
  171.       if line ~= '' then do
  172.          ttc = ttc + 1
  173.          matches.ttc = line
  174.       end
  175.    end
  176.    close(datafile)
  177. end
  178. else do
  179.    say
  180.    say cum_error
  181.    say
  182.    say cum_t3"'"input_file"'"cum_t4
  183.    exit
  184. end
  185.  
  186. /* parsing matches array for errors */
  187.  
  188. errors  = ' '
  189. errct   = 0
  190. legs    = 0
  191.  
  192. do i=1 to ttc
  193.    mkr = 0
  194.    if pos("#Round=",matches.i) > 0 then do
  195.       if pos("1st Leg",matches.i) > 0 then
  196.          legs = 1
  197.       if pos("2nd Leg",matches.i) > 0 then
  198.          legs = 2
  199.    end
  200.    if pos('#',matches.i) = 0 then do
  201.       sh  = substr(matches.i,32,2)
  202.       sa  = substr(matches.i,37,2)
  203.  
  204.       if sa  = sh then mkr = 1
  205.       if sa ~= sh & legs~=2 then iterate
  206.       if sa ~=sh & legs=2 then mkr = 1
  207.       if pos(not_played,matches.i) > 0 then mkr = 3   /* was 0 - unsure why... */
  208.  
  209.    /* this is where the check for away goals and if its equal after two legs */
  210.    /* if so then extra time then penalties needs to be played. */
  211.    /* sa and sh need to be added together with the 1st leg before checking */
  212.    /* if no winner, (if away goals set), check away goals else proceed onto */
  213.    /* extra time and penalties */
  214.  
  215.       if mkr = 1 & legs = 1 then iterate
  216.       if mkr = 1 & legs = 2 then do
  217.          j = i + 1
  218.          if pos("#1st Leg",matches.j) > 0 then do
  219.             i = j
  220.             fh  = substr(matches.i,32,2)
  221.             fa  = substr(matches.i,37,2)
  222.             shs = fh + sh
  223.             sas = fa + sa
  224.  
  225.             if shs = sas then do
  226.                if pos("YES",awayg) > 0 then do
  227.                   if fh = sa then mkr = 1
  228.                   if fh ~= sa then iterate
  229.                end
  230.                else
  231.                   mkr = 1
  232.             end
  233.             if shs ~= sas then iterate
  234.             if pos(not_played,matches.i) > 0 then mkr = 3
  235.          end
  236.          else do
  237.             errct = errct + 1
  238.             errors = errors" "i" "
  239.             iterate
  240.          end
  241.       end
  242.  
  243.       if mkr = 1 then do
  244.          j = i + 1
  245.          if pos("#Score After Extra Time",matches.j) > 0 then do
  246.             i = i + 1
  247.             eh  = substr(matches.i,32,2)
  248.             ea  = substr(matches.i,37,2)
  249.             if eh = "" | ea = "" then mkr = 3
  250.             if pos(not_played,matches.i) > 0 then mkr = 3
  251.  
  252.             if mkr ~= 3 then do
  253.                if legs = 2 then do
  254.                   shs = fh + eh
  255.                   sas = fa + ea
  256.                   if shs ~= sas then iterate
  257.                   if pos("YES",awayg) > 0 then do
  258.                      if eh = sa then do
  259.                         if eh = eh & sa = ea then
  260.                            mkr = 1
  261.                         else
  262.                            iterate
  263.                      end
  264.                      if eh ~= sa then iterate
  265.                   end
  266.                   else
  267.                      mkr = 1
  268.                end
  269.                else do
  270.                   if eh =  ea then mkr = 1
  271.                   if eh ~= ea then iterate
  272.                end
  273.             end
  274.             if eh < sh | ea < sa then mkr = 3
  275.          end
  276.       end
  277.       if mkr = 3 then do
  278.          errct = errct + 1
  279.          errors = errors" "i" "
  280.          iterate
  281.       end
  282.       if mkr = 1 then do
  283.          j = i + 1
  284.          if pos("#Penalties",matches.j) > 0 then do
  285.             i = i + 1
  286.             ph  = substr(matches.i,32,2)
  287.             pa  = substr(matches.i,37,2)
  288.             if ph = "" | pa = "" then mkr = 3
  289.  
  290.             if ph =  pa then mkr = 3
  291.             if ph ~= pa then iterate
  292.             if pos(not_played,matches.i) > 0 then mkr = 3
  293.          end
  294.       end
  295.       if mkr = 3 then do
  296.          errct = errct + 1
  297.          errors = errors" "i" "
  298.          iterate
  299.       end
  300.    end
  301. end
  302.  
  303. if errct > 0 then do
  304.    say
  305.    say center(cum_t6"'"league_stuff"'",78)
  306.    say "-------------------------------------------------------------------------------"
  307.    say
  308.    do j=1 to ttc
  309.       if pos("#Round",matches.j) = 0 then do
  310.          if pos(" "j" ",errors) > 0 then
  311.             say ">"left(matches.j,70)""cum_t7
  312.          else
  313.             say ">"left(matches.j,70)"<"
  314.       end
  315.    end
  316.    say
  317.    say
  318.    say errct" "cum_t8
  319.    say
  320.    say cum_t9
  321.    say cum_t10
  322.    say
  323.    say "1. "cum_t11
  324.    say "   "cum_t12
  325.    say "2. "cum_t13
  326.    say "   "cum_t14
  327.    say "3. "cum_t15
  328.    say "   "cum_t16
  329.    say "4. "cum_t17
  330.    say "   "cum_t18
  331.    say "5. "cum_t19
  332.    say "   "cum_t20
  333.    say "6. "cum-t21
  334.    say "   "cum_t22
  335.    say "7. "cum_t23
  336.    say "   "cum_t24
  337.    say "8. "cum_t25
  338.    say "   "cum_t26
  339.    say "9. "cum_t27
  340.    say
  341.    say cum_t28
  342.    say cum_t29
  343.    say
  344.    say "-------------------------------------------------------------------------------"
  345.    exit
  346. end
  347.  
  348. secount = 0
  349. if open(datafile,league_file||input2_file,'r') then do
  350.    do while ~eof(datafile)
  351.       line = readln(datafile)
  352.       secount         = secount + 1
  353.       selines.secount = line
  354.    end
  355.    close(datafile)
  356. end
  357. else do
  358.    say
  359.    say cum_error
  360.    say
  361.    say cum_t3"'"league_file||input2_file"'"cum_t4
  362.    exit
  363. end
  364.  
  365. address command 'delete >NIL: 'input_file
  366.  
  367. et. = '???'
  368. pn. = '???'
  369. do j=1 to secount
  370.    mkr = 0
  371.    if pos(separator,selines.j) = 0 then do
  372.       shome = strip(substr(selines.j,1,30))
  373.       saway = strip(substr(selines.j,41,30))
  374.       do i=1 to ttc
  375.          home  = strip(substr(matches.i,1,30))
  376.          away  = strip(substr(matches.i,41,30))
  377.          mkr = 0
  378.  
  379.          if shome = home & saway = away then do
  380.             if pos(not_played,selines.j) > 0 then do
  381.                selines.j = matches.i
  382.                mkr = 1
  383.             end
  384.             g = i + 1
  385.             if pos("#1st Leg",matches.g) > 0 then do
  386.                a = j + 1
  387.                dif = 1
  388.             end
  389.             else do
  390.                a = j
  391.                dif = 0
  392.             end
  393.             if mkr = 1 then do
  394.                k = i + 1 + dif
  395.                if pos("#Score After Extra Time",matches.k) > 0 & pos(not_played,matches.k) = 0 then
  396.                   et.a = matches.k
  397.                k = k + 1
  398.                if pos("#Penalties",matches.k) > 0 & pos(not_played,matches.k) = 0 then
  399.                   pn.a = matches.k
  400.             end
  401.          end
  402.          if mkr = 1 then leave
  403.       end
  404.    end
  405. end
  406.  
  407. if selines.secount ~='' & selines.secount ~='*' then do
  408.    secount = secount + 1
  409.    sdlines.secount = "*"
  410. end
  411. if open(datafile,league_file||input2_file,'w') then do
  412.    do j=1 to secount
  413.       if selines.j~='' then do
  414.          writeln(datafile,selines.j)
  415.          if pos("???",et.j) = 0 & et.j ~= "" then
  416.             writeln(datafile,et.j)
  417.          if pos("???",pn.j) = 0 & pn.j ~= "" then
  418.             writeln(datafile,pn.j)
  419.       end
  420.    end
  421.    close(datafile)
  422. end
  423. else do
  424.    say
  425.    say cum_error
  426.    say
  427.    say cum_t3"'"league_file || input2_file"'"cum_t5
  428. end
  429.  
  430. exit